<?php

/**
 * Beca filter form.
 *
 * @package    BecArTe
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class BecaFormFilter extends BaseBecaFormFilter
{
  public function configure()
  {
    $this->widgetSchema['anio'] = new sfWidgetFormFilterInput(array(
        'with_empty' => false,
        'label' => 'Año'
    ));            
    $this->validatorSchema['anio'] = new sfValidatorSchemaFilter(
        'text',
        new sfValidatorInteger(array(
            'required' => false,
            'min' => 1990,
            'max' => 2050
            ))
    );
    $this->widgetSchema['estado'] = new sfWidgetFormChoice(array(
        'choices' => array(
            '' => 'Todos',
            'En Inscripción' => 'En Inscripción',
            'Vigentes' => 'Vigentes',
            'Finalizadas' => 'Finalizadas'
         )
    ));            
    $this->validatorSchema['estado'] = new sfValidatorChoice(array(
        'choices' => array('','En Inscripción','Vigentes','Finalizadas'),
        'required' => false,
        'multiple' => false
    ));
    $this->widgetSchema['categoria_id']->setOption('order_by', array('nombre', 'ASC'));
  }
  
  
  public function addAnioColumnQuery($query, $field, $value) {
    if(!is_null($value['text'])) $query->andWhere("? BETWEEN YEAR(fecha_inicio) AND YEAR(fecha_fin)", $value['text']);
  }
    
  public function addEstadoColumnQuery($query, $field, $value) {
    if($value == 'En Inscripción') {
      $query->andWhere("fecha_limite_inscripcion >= DATE(NOW())");
    } elseif($value == 'Vigentes') {
      $query->andWhere("DATE(NOW()) BETWEEN fecha_inicio AND fecha_fin");
    } elseif($value == 'Finalizadas') {
      $query->andWhere("DATE(NOW()) > fecha_fin");
    }
  }
  
}
